# _*_ coding:utf-8 _*_
# @Time  : 2022.11.10
# @Author: zizlee

# 上期所交易日查询
import datetime
import json

from iFinDPy import THS_Date_Query, THS_iFinDLogout, THS_iFinDLogin


def get_days(start, end):
    ret = THS_Date_Query('212020008','mode:1,dateType:0,period:D,dateFormat:0', start, end)
    days = ret.data.split(',')

    exclude_exchange_days = []
    s = datetime.date(2022, 1, 1)
    e = datetime.date(2022, 12, 31)
    while s <= e:
        if s.strftime('%Y-%m-%d') not in days:
            exclude_exchange_days.append(s.strftime('%Y-%m-%d'))
        s = s + datetime.timedelta(days=1)
    with open('非交易日.json', 'w', encoding='utf8') as fp:
        json.dump(exclude_exchange_days, fp, indent=4)


if __name__ == '__main__':
    with open('../PlatRj/ths.config.json', 'r', encoding='utf8') as cf:
        config = json.load(cf)

    THS_iFinDLogin(config['USER'], config['PSWD'])
    get_days('2022-01-01', '2022-12-31')
    THS_iFinDLogout()
